<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<!-- bootstrap样式、主题、核心文档 -->
<link rel="stylesheet" href="../libs/bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="../libs/bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css" />
<script type="text/javascript" src="../libs/bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../libs/jquery/jquery.js"></script>
<style type="text/css">
	.jumbotron{
		height:400px;
	}
	.btn.btn-info{
		width:300px;
		font-size: 20px;
	}
	.inner{
		float:left;
		height:300px;
		
		
	}
	#inner2{
		background-color: white;
	}
	
	.container{
		margin-left: 0;
		margin-right: 0;
		width:100%;
	}
</style>
</head>
<body>
	<div class="jumbotron container">
		<div style="width:40%; margin-left: 85px;" class="inner">
			<p>消费类型:<span></span></p>	
			<p>金额:<span></span></p>		
			<p>时长:<span></span></p>
			<p>月利息:<span></span></p>
			<p><span></span></p>
			<p><span></span></p>
			<p><span></span></p>
			<p><span></span></p>
		</div>
		<div style="width:50%;" class="inner jumbotron" id="inner2">
			<h2><i>审核快、放款快、利息低</i></h2>
			<h2>轻松解决您的当务之急</h2>
			<h2>助您一<span style="font-size: 36px; color: gold">'笔'</span>之力</h2>
		</div>
	</div>
	<script type="text/javascript">
	$(function(){
		var userid = "${user.id}";//用户的唯一id
		var days = "${user.currentdate}";//当前的日期
		alert(days);
		$.ajax({
			type:"post",
			url:"../LoanbillInfoPersonalServlet",
			data:"userid="+userid,
			dataType:"json",
			success:function(lb){
				lbid = lb.id;
				var rate=lb.monthrate*100;
				rate = rate.toFixed(2)+"%";
				$("span").eq(0).html(lb.name);
				$("span").eq(1).html("￥"+lb.money+"元");
				$("span").eq(2).html(lb.duration+"个月");
				$("span").eq(3).html(rate);
				$("span").eq(4).html(lb.successstate==0?"信息发布时间："+lb.starttime:"借款开始时间："+lb.succstarttime);
				$("span").eq(5).html(lb.successstate==0?"信息截止时间："+lb.endtime:"借款结束时间："+lb.succendtime);
				$("span").eq(6).html(lb.successstate==0?"您的借款正在审核中.....":"正在还款中.....");
				$("span").eq(7).html(lb.successstate==0||days<11?"":"<button class='btn btn-success'>我要还款</button>");
			}
			
		});
		
		$("button").live("click",function(){
			//根据借款单id查询还款信息
			$.post("../RefundCurrentServlet",{loanbillid:lbid},function(refund){
				if(refund==null){
					$("span").eq(6).html("本期已经还清");
				}else{
					var money = prompt("您的还款进度为第"+refund.months+"期，金额"+refund.money.toFixed(2)+"元");
					if(money==null){
						alert("输入金额不能为空");
					}else{
						//还款，主要修改数据库的realtime
						$.post("../RefundUpdateServlet",{refundid:refund.id},function(result){
							if(result.flag){
								alert(result.message);
								$("span").eq(6).html("本期已经还清");
							}else{
								alert("服务器繁忙，请稍后再试....");
							}
						},"json");
					}
				}
				
			},"json");
		});
		
	})
	
	</script>
</body>

</html>